/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
window.onload = function ()
{
    setPage();
};

function extractPageName(hrefString)
{
    var arr = hrefString.split('/');
    return  (arr.length < 2) ? hrefString : arr[arr.length - 2].toLowerCase() + arr[arr.length - 1].toLowerCase();
}

function setActiveMenu(arr, crtPage)
{
    for (var i = 0; i < arr.length; i++)
    {
        var ulChilds = arr[i].getElementsByTagName("ul");
        var aChilds = undefined;
        if (ulChilds.length > 0) {
            aChilds = ulChilds[0].getElementsByTagName("a");
            for (var j = 0; j < aChilds.length; j++)
            {
                if (extractPageName(aChilds[j].href) == crtPage)
                {                
                    arr[i].className = "current";
                }
            }
        }
        
        if (extractPageName(arr[i].firstChild.href) == crtPage)
        {
            arr[i].className = "current";
        }
        
        if (aChilds != undefined)
        {
            i += aChilds.length;
        }
    }
}

function setPage()
{
    hrefString = document.location.href ? document.location.href : document.location;

    if (document.getElementById("nav") != null)
        setActiveMenu(document.getElementById("nav").getElementsByTagName("li"), extractPageName(hrefString));
}

